import requests

class FeiShuWebhook:
    def __init__(self, webhook_url):
        self.webhook_url = webhook_url

    def send(self, text):
        data = {
            "content": {
                "text": text
            },
            "msg_type": "text"
        }

        response = requests.post(
            self.webhook_url,
            json=data,  # 自动将字典转为JSON并设置Content-Type
            headers={"Content-Type": "application/json"}
        )

        if response.status_code == 200:
            print("Webhook调用成功")
            print(response.text)
        else:
            print(f"调用失败: {response.status_code}")


def demo():
    # Webhook URL
    webhook_url = "https://open.feishu.cn/open-apis/bot/v2/hook/a1393a38-5ca6-46c9-b7d3-8746e0175a5a"

    # 准备数据
    data = {
        "content": {
            "text": "Hello from Python"
        },
        "msg_type": "text"
    }

    # 发送 POST 请求
    response = requests.post(
        webhook_url,
        json=data,  # 自动将字典转为JSON并设置Content-Type
        headers={"Content-Type": "application/json"}
    )

    # 检查响应
    if response.status_code == 200:
        print("Webhook调用成功")
        print(response.text)
    else:
        print(f"调用失败: {response.status_code}")

def main():
    webhook = FeiShuWebhook("https://open.feishu.cn/open-apis/bot/v2/hook/a1393a38-5ca6-46c9-b7d3-8746e0175a5a")
    webhook.send("Hello from Python")
